import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: "/",
    name: "home",
    meta: {
      title: "首页",
      keepAlive: false, // 需要缓存
    },
    component: HomeView,
  },
  {
    path: "/home",
    name: "home",
    meta: {
      title: "首页",
      keepAlive: false, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component:  HomeView,
  },
  {
    path: "/tab",
    name: "tab",
    meta: {
      title: "tab切换",
      keepAlive: true, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ "../views/Tab.vue"),
  },
  {
    path: "/table",
    name: "table",
    meta: {
      title: "表格",
      keepAlive: false, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/Table.vue"),
  },
  {
    path: "/exportDemo",
    name: "exportDemo",
    meta: {
      title: "导入案例",
      keepAlive: false, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/exportDemo.vue"),
  },
  {
    path: "/chart",
    name: "Chart",
    meta: {
      title: "图表",
      keepAlive: false, // 不需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/Chart.vue"),
  },
  {
    path: "/toson",
    name: "toson",
    meta: {
      title: "父组件到子",
      keepAlive: false, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/FtoS/index.vue"),
  },
  {
    path: "/actionson",
    name: "actionson",
    meta: {
      title: "父操作子",
      keepAlive: false, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/FactionS/index.vue"),
  },
  {
    path: "/tree",
    name: "tree",
    meta: {
      title: "ulli树组件",
      keepAlive: false, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/tree/index.vue"),
  },
  {
    path: "/tofather",
    name: "tofather",
    meta: {
      title: "子组件操作父组件",
      keepAlive: false, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/StoF/index.vue"),
  },
  {
    path: "/brother",
    name: "brother",
    meta: {
      title: "兄弟组件",
      keepAlive: false, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/Brother/index.vue"),
  },
  {
    path: "/activeCom",
    name: "activeCom",
    meta: {
      title: "动态组件",
      keepAlive: true, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/activeCom/index.vue"),
  },
  {
    path: "/slot",
    name: "slot",
    meta: {
      title: "插槽",
    },
    component: () => import(/* webpackChunkName: "about" */ "../views/slot/index.vue"),
  },
  {
    path: "/filter",
    name: "filter",
    meta: {
      title: "过滤",
      keepAlive: true, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/filter/index.vue"),
  },
  {
    path: "/vuex",
    name: "vuex",
    meta: {
      title: "VUEX",
      keepAlive: true, // 需要缓存
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/vuex/index.vue"),
  },
];

const router = new VueRouter({
  linkActiveClass:'active',//路由默认样式
  routes
})

//beforeEach 函数有三个参数：
// to:router即将进入的路由对象
//from:当前导航即将离开的路由
//next: Function,进行管道中的一个钩子，如果执行完了，则导航的状态就是confirmed (确认的)
//afterEach 函数 不用传next()函数
router.beforeEach(function(to,from,next){
  console.log(12345);
  // if(!sessionStorage.getItem('sign')){
  //   if(to.path !== '/'){
  //     alert('请签到')
  //     next();
  //   }
  // }
  next();
})

export default router
